/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Shell;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Oho
 */
public class ExecuteShell extends Thread{
    Socket sk;
    public ExecuteShell(Socket soc){
        this.sk=soc;
    }
    public void run(){
        BufferedReader inputServer = null;
        try {
            inputServer = new BufferedReader(new InputStreamReader(sk.getInputStream()));
            do{
                String lenh;
                lenh=inputServer.readLine();
                if(lenh.compareTo("shut down")==0)
                    {
                        ProcessBuilder processBuilder = new ProcessBuilder("shutdown","/s");
                        try {
                            processBuilder.start();
                        } catch (IOException e) {

                        }
                    }
                    if(lenh.compareTo("restart")==0){
                        ProcessBuilder processBuilder = new ProcessBuilder("shutdown","/r");
                        try {
                            processBuilder.start();
                        } catch (IOException e) {

                        }
                    }
                    if(lenh.compareTo("log off")==0){
                        ProcessBuilder processBuilder = new ProcessBuilder("shutdown","/l");
                        try {
                            processBuilder.start();
                        } catch (IOException e) {

                        }
                    }
                }while(true);
        } catch (IOException ex) {
            Logger.getLogger(ExecuteShell.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            try {
                inputServer.close();
            } catch (IOException ex) {
                Logger.getLogger(ExecuteShell.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
    
}
